import django_filters

from users.models import CustomerUser, User, Level
from activities.models import *
from merchants.models import *
from goods.models import LaunchedGoods, Goods
from orders.models import OrderInfo
from vouchers.models import AliDiscountCoupon, AliDiscountCouponLevel, AliDiscountCouponInfo, AliDiscountCouponMerchant, CustomizeActivity, CustomizeActivityFlipCARDS, UpdateStockUsableMerchant
from cashbonus.models import CashActivity, CashActivityData, CashActivityLevel, CashActivityLevelRecord, CashActivityWhiteTable


class CustomerUserFilter(django_filters.rest_framework.FilterSet):
    '''C端用户资料过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = CustomerUser
        fields = ('create_time_begin', 'create_time_end')


class ActivityDataFilter(django_filters.rest_framework.FilterSet):
    '''邮米派发过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    activity = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')
    companyuser_id = django_filters.BaseInFilter(field_name='companyuser_id', lookup_expr='in')

    class Meta:
        model = ActivityData
        fields = ('create_time_begin', 'create_time_end', 'companyuser_id', 'state')


class ManagerUserFilter(django_filters.rest_framework.FilterSet):
    '''客户经理料过滤'''

    is_active = django_filters.BaseInFilter(field_name='is_active', lookup_expr='in')
    role_id = django_filters.BaseInFilter(field_name='role_id', lookup_expr='in')

    class Meta:
        model = User
        fields = ('is_active', 'role_id')


class LevelFilter(django_filters.rest_framework.FilterSet):
    '''客户经理料过滤'''

    merchant_id = django_filters.BaseInFilter(field_name='merchantenter__merchant_id', lookup_expr='in')

    class Meta:
        model = Level
        fields = ('merchant_id',)


class MerchantFilter(django_filters.rest_framework.FilterSet):
    '''商户过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    is_mall = django_filters.BaseInFilter(field_name='is_mall', lookup_expr='in')

    class Meta:
        model = Merchant
        fields = ('create_time_begin', 'create_time_end', 'is_mall')


class LaunchedGoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    goods_id = django_filters.BaseInFilter(field_name='goods_id', lookup_expr='in')

    class Meta:
        model = LaunchedGoods
        fields = ('create_time_begin', 'create_time_end', 'goods_id')


class GoodsFilter(django_filters.rest_framework.FilterSet):
    '''商品过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    is_launched = django_filters.BaseInFilter(field_name='is_launched', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')

    class Meta:
        model = Goods
        fields = ('create_time_begin', 'create_time_end', 'merchant_id', 'is_launched', 'order_species')


class OrderInfoFilter(django_filters.rest_framework.FilterSet):
    '''订单过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    success_time_begin = django_filters.DateTimeFilter(field_name="success_time__date", lookup_expr='gte')
    success_time_end = django_filters.DateTimeFilter(field_name="success_time__date", lookup_expr='lte')
    payment_time_begin = django_filters.DateTimeFilter(field_name="payment_time__date", lookup_expr='gte')
    payment_time_end = django_filters.DateTimeFilter(field_name="payment_time__date", lookup_expr='lte')
    use_time_begin = django_filters.DateTimeFilter(field_name="use_time__date", lookup_expr='gte')
    use_time_end = django_filters.DateTimeFilter(field_name="use_time__date", lookup_expr='lte')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    total_price_min = django_filters.NumberFilter(field_name="total_price", lookup_expr='gte')
    total_price_max = django_filters.NumberFilter(field_name="total_price", lookup_expr='lte')
    customeruser_id = django_filters.BaseInFilter(field_name='customer_user_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')
    bill_id = django_filters.BaseInFilter(field_name='bill_id', lookup_expr='in')
    goods_id = django_filters.BaseInFilter(field_name='ordergoods__goods_id', lookup_expr='in')
    order_species = django_filters.BaseInFilter(field_name='order_species', lookup_expr='in')

    class Meta:
        model = OrderInfo
        fields = ('create_time_begin', 'create_time_end', 'state', 'total_price_min', 'total_price_max', 'customeruser_id', 'merchant_id', 'bill_id', 'goods_id',
                  'success_time_begin', 'success_time_end', 'use_time_begin', 'use_time_end', 'order_species')


class MerchantBillFilter(django_filters.rest_framework.FilterSet):
    '''商户账单'''

    receipts_time_begin = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='gte')
    receipts_time_end = django_filters.DateTimeFilter(field_name="receipts_time__date", lookup_expr='lte')
    bill_state = django_filters.BaseInFilter(field_name='bill_state', lookup_expr='in')
    bill_type = django_filters.BaseInFilter(field_name='bill_type', lookup_expr='in')
    payable_amount_min = django_filters.NumberFilter(field_name="payable_amount", lookup_expr='gte')
    payable_amount_max = django_filters.NumberFilter(field_name="payable_amount", lookup_expr='lte')
    level_id = django_filters.BaseInFilter(field_name='merchant__level_id', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')

    class Meta:
        model = MerchantBill
        fields = ('receipts_time_begin', 'receipts_time_end', 'bill_state', 'payable_amount_min', 'payable_amount_max', 'level_id', 'merchant_id', 'bill_type')


class AliDiscountCouponFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    coupon_status = django_filters.BaseInFilter(field_name='coupon_status', lookup_expr='in')
    coupon_channel = django_filters.BaseInFilter(field_name='coupon_channel', lookup_expr='in')
    coupon_way = django_filters.BaseInFilter(field_name='coupon_way', lookup_expr='in')

    class Meta:
        model = AliDiscountCoupon
        fields = ('coupon_status', 'coupon_channel', 'coupon_way')


class CashActivityFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_state = django_filters.BaseInFilter(field_name='activity_state', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = CashActivity
        fields = ('activity_state', 'activity_type')


class CashActivityLevelFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_id = django_filters.BaseInFilter(field_name='cash_activity_id', lookup_expr='in')
    dimensionality = django_filters.BaseInFilter(field_name='level__level', lookup_expr='in')

    class Meta:
        model = CashActivityLevel
        fields = ('activity_id', 'dimensionality')


class AliDiscountCouponLevelFilter(django_filters.rest_framework.FilterSet):
    '''活动过滤'''

    activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponLevel
        fields = ('activity_id', )


class CashActivityDataFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    # cash_activity_level_id = django_filters.BaseInFilter(field_name='cash_activity_level_id', lookup_expr='in')
    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    level_id = django_filters.BaseInFilter(field_name='level_id', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='cash_activity_id', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = CashActivityData
        fields = ('state', 'level_id', 'activity_id', 'create_time_begin', 'create_time_end')


class CashActivityLevelRecordFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    cash_activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')
    cash_activity_level_id = django_filters.BaseInFilter(field_name='activity_level_id', lookup_expr='in')
    operation_type = django_filters.BaseInFilter(field_name='operation_type', lookup_expr='in')

    class Meta:
        model = CashActivityLevelRecord
        fields = ('create_time_begin', 'create_time_end', 'cash_activity_id', 'cash_activity_level_id', 'operation_type')


class AliDiscountCouponInfoFilter(django_filters.rest_framework.FilterSet):
    '''领取明细过滤'''

    alidiscountcoupon_level_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_level_id', lookup_expr='in')
    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')
    level_id = django_filters.BaseInFilter(field_name='level_id', lookup_expr='in')
    activity_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')
    coupon_channel = django_filters.BaseInFilter(field_name='coupon_channel', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponInfo
        fields = ('alidiscountcoupon_level_id', 'status', 'level_id', 'activity_id', 'coupon_channel')


class ChannelFilter(django_filters.rest_framework.FilterSet):

    channel_type = django_filters.BaseInFilter(field_name='channel_type', lookup_expr='in')

    class Meta:
        model = Channel
        fields = ('channel_type',)


class AliDiscountCouponMerchantFilter(django_filters.rest_framework.FilterSet):

    alidiscountcoupon_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = AliDiscountCouponMerchant
        fields = ('alidiscountcoupon_id',)


class WaivePaymentActivityFilter(django_filters.rest_framework.FilterSet):

    activity_state = django_filters.BaseInFilter(field_name='activity_state', lookup_expr='in')

    class Meta:
        model = WaivePaymentActivity
        fields = ('activity_state',)


class WaivePaymentAdvanceFilter(django_filters.rest_framework.FilterSet):

    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')
    operate_type = django_filters.BaseInFilter(field_name='operate_type', lookup_expr='in')

    class Meta:
        model = WaivePaymentAdvance
        fields = ('waivepaymentactivity_id', 'operate_type')


class WaivePaymentMerchantFilter(django_filters.rest_framework.FilterSet):

    payment_state = django_filters.BaseInFilter(field_name='payment_state', lookup_expr='in')
    waivepaymentadvance_id = django_filters.BaseInFilter(field_name='waivepaymentadvance_id', lookup_expr='in')
    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')

    class Meta:
        model = WaivePaymentMerchant
        fields = ('payment_state', 'waivepaymentadvance_id', 'waivepaymentactivity_id')


class WaivePaymentOrderFilter(django_filters.rest_framework.FilterSet):

    waivepaymentmerchant_id = django_filters.BaseInFilter(field_name='waivepaymentmerchant_id', lookup_expr='in')
    waivepaymentactivity_id = django_filters.BaseInFilter(field_name='waivepaymentactivity_id', lookup_expr='in')
    is_hit = django_filters.BaseInFilter(field_name='is_hit', lookup_expr='in')

    class Meta:
        model = WaivePaymentOrder
        fields = ('waivepaymentmerchant_id', 'waivepaymentactivity_id', 'is_hit')


class CustomizeActivityFilter(django_filters.rest_framework.FilterSet):

    activity_status = django_filters.BaseInFilter(field_name='activity_status', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = CustomizeActivity
        fields = ('activity_status', 'activity_type')


class CustomizeActivityFlipCARDSFilter(django_filters.rest_framework.FilterSet):

    open_status = django_filters.BaseInFilter(field_name='open_status', lookup_expr='in')
    customizeactivity_id = django_filters.BaseInFilter(field_name='customizeactivity_id', lookup_expr='in')

    class Meta:
        model = CustomizeActivityFlipCARDS
        fields = ('open_status', 'customizeactivity_id')


class MerchantSettlementRecordFilter(django_filters.rest_framework.FilterSet):

    settlement_time_begin = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='gte')
    settlement_time_end = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='lte')
    settlement_time = django_filters.DateTimeFilter(field_name="settlement_time__date", lookup_expr='gt')
    status = django_filters.BaseInFilter(field_name='status', lookup_expr='in')
    channel_id = django_filters.BaseInFilter(field_name='channel_id', lookup_expr='in')
    is_bind = django_filters.BaseInFilter(field_name='is_bind', lookup_expr='in')
    merchant_id = django_filters.BaseInFilter(field_name='merchant_id', lookup_expr='in')

    class Meta:
        model = MerchantSettlementRecord
        fields = ('settlement_time_begin', 'settlement_time_end', 'status', 'channel_id', 'is_bind', 'settlement_time', 'merchant_id')


class MerchantEightEightDrawFilter(django_filters.rest_framework.FilterSet):

    state = django_filters.BaseInFilter(field_name='state', lookup_expr='in')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')
    amount_min = django_filters.NumberFilter(field_name="amount", lookup_expr='gte')
    amount_max = django_filters.NumberFilter(field_name="amount", lookup_expr='lte')
    activity_id = django_filters.BaseInFilter(field_name='activity_id', lookup_expr='in')

    class Meta:
        model = MerchantEightEightDraw
        fields = ('state', 'create_time_begin', 'create_time_end', 'amount_min', 'amount_max', 'activity_id')


class MerchantBusinessQRCodeFilter(django_filters.rest_framework.FilterSet):

    is_bind = django_filters.BaseInFilter(field_name='is_bind', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantBusinessQRCode
        fields = ('is_bind', 'bind_time_begin', 'bind_time_end')


class UpdateStockUsableMerchantFilter(django_filters.rest_framework.FilterSet):
    '''添加用户申请单过滤'''

    activity_id = django_filters.BaseInFilter(field_name='alidiscountcoupon_id', lookup_expr='in')

    class Meta:
        model = UpdateStockUsableMerchant
        fields = ('activity_id', )


class MerchantEightEightActivityFilter(django_filters.rest_framework.FilterSet):

    activity_status = django_filters.BaseInFilter(field_name='activity_status', lookup_expr='in')
    activity_type = django_filters.BaseInFilter(field_name='activity_type', lookup_expr='in')

    class Meta:
        model = MerchantEightEightActivity
        fields = ('activity_status', 'activity_type')


class MerchantBankQRCodeQuestFilter(django_filters.rest_framework.FilterSet):

    file_type = django_filters.BaseInFilter(field_name='file_type', lookup_expr='in')
    file_status = django_filters.BaseInFilter(field_name='file_status', lookup_expr='in')

    class Meta:
        model = MerchantBankQRCodeQuest
        fields = ('file_type', 'file_status')


class MerchantBankQRCodeBindDataFilter(django_filters.rest_framework.FilterSet):

    card_type = django_filters.BaseInFilter(field_name='card_type', lookup_expr='in')
    is_first = django_filters.BaseInFilter(field_name='is_first', lookup_expr='in')
    bank_qrcode_id = django_filters.BaseInFilter(field_name='bank_qrcode_id', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MerchantBankQRCodeBindData
        fields = ('card_type', 'is_first', 'bind_time_begin', 'bind_time_end', 'bank_qrcode_id')


class MerchantBankQRCodeFilter(django_filters.rest_framework.FilterSet):

    is_download = django_filters.BaseInFilter(field_name='is_download', lookup_expr='in')

    class Meta:
        model = MerchantBankQRCode
        fields = ('is_download',)


class MErchantBankQPCodeStatisticsFilter(django_filters.rest_framework.FilterSet):

    bank_qrcode_id = django_filters.BaseInFilter(field_name='bank_qrcode_id', lookup_expr='in')
    bind_time_begin = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='gte')
    bind_time_end = django_filters.DateTimeFilter(field_name="bind_time__date", lookup_expr='lte')

    class Meta:
        model = MErchantBankQPCodeStatistics
        fields = ('bind_time_begin', 'bind_time_end', 'bank_qrcode_id')


class LuckyBagChildActivityDataFilter(django_filters.rest_framework.FilterSet):

    lucky_status = django_filters.BaseInFilter(field_name='lucky_status', lookup_expr='in')
    luckybagchildactivity_id = django_filters.BaseInFilter(field_name='luckybagchildactivity_id', lookup_expr='in')
    merchantuser_id = django_filters.BaseInFilter(field_name='merchantuser_id', lookup_expr='in')
    lucky_bag_max = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='lte')
    lucky_bag_min = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='gte')
    received_time_begin = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='gte')
    received_time_end = django_filters.DateTimeFilter(field_name="received_time__date", lookup_expr='lte')

    class Meta:
        model = LuckyBagChildActivityData
        fields = ('lucky_status', 'lucky_bag_max', 'lucky_bag_min', 'luckybagchildactivity_id', 'received_time_begin', 'received_time_end', 'merchantuser_id')


class LuckyBagRecordFilter(django_filters.rest_framework.FilterSet):

    operate_type = django_filters.BaseInFilter(field_name='operate_type', lookup_expr='in')
    merchantuser_id = django_filters.BaseInFilter(field_name='merchantuser_id', lookup_expr='in')
    lucky_bag_max = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='lte')
    lucky_bag_min = django_filters.NumberFilter(field_name="lucky_bag", lookup_expr='gte')
    create_time_begin = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='gte')
    create_time_end = django_filters.DateTimeFilter(field_name="create_time__date", lookup_expr='lte')

    class Meta:
        model = LuckyBagRecord
        fields = ('operate_type', 'lucky_bag_max', 'lucky_bag_min', 'create_time_begin', 'create_time_end', 'merchantuser_id')


class MerchantNFCDeviceTradeFilter(django_filters.rest_framework.FilterSet):

    trade_time_begin = django_filters.DateTimeFilter(field_name="trade_time__date", lookup_expr='gte')
    trade_time_end = django_filters.DateTimeFilter(field_name="trade_time__date", lookup_expr='lte')
    total_amount_max = django_filters.NumberFilter(field_name="total_amount", lookup_expr='lte')
    total_amount_min = django_filters.NumberFilter(field_name="total_amount", lookup_expr='gte')

    class Meta:
        model = MerchantNFCDeviceTrade
        fields = ('trade_time_begin', 'trade_time_end', 'total_amount_max', 'total_amount_min')


class CashActivityWhiteTableFilter(django_filters.rest_framework.FilterSet):

    cashactivity_id = django_filters.BaseInFilter(field_name='cashactivity_id', lookup_expr='in')
    is_admin = django_filters.BaseInFilter(field_name='is_admin', lookup_expr='in')

    class Meta:
        model = CashActivityWhiteTable
        fields = ('cashactivity_id', 'is_admin')